package com.docker.sys.app;

import com.docker.core.constant.APPIDConstant;
import com.docker.core.mvc.APPID;
import com.docker.core.mvc.Remark;
import com.docker.core.mvc.controller.BaseAPIController;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Okv;
import com.jfinal.kit.StrKit;

/**
 * @Author ldl
 * @Create 2020/09/18 018 14:16
 */
@Remark("系统应用管理")
@APPID(APPIDConstant.dum_web)
public class AppController extends BaseAPIController {

    @Inject
    private AppService appService;

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 14:41
     */
    @Remark("应用分页列表")
    public void paginate() {
        Okv cond = Okv.create().set("a.user_token = ", getPara("user_token"));
        if (StrKit.notBlank(getPara("app_name"))) {
            cond.set("a.app_name like ", "%" + getPara("app_name") + "%");
        }
        renderAPISuccess(appService.paginate(Okv.by("cond", cond), getPageNum(), getPageSize()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/11/04 004 12:04
     */
    @Remark("下拉列表")
    public void look() {
        Okv cond = Okv.create().set("a.status_flag = ", "1");
        renderAPISuccess(appService.look(Okv.by("cond", cond)));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 14:42
     */
    @Remark("新增应用")
    public void save() {
        renderAPI(appService.save(getBean(AppBean.class, ""), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 14:54
     */
    @Remark("修改应用")
    public void update() {
        renderAPI(appService.update(getBean(AppBean.class, ""), getPara("app_id_ex"), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 14:57
     */
    @Remark("获取应用密钥")
    public void secret() {
        renderAPISuccess(appService.secret(getPara("app_id_ex")));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 14:59
     */
    @Remark("同步至缓存")
    public void cache() {
        renderAPI(appService.cache());
    }

}
